package com.winchain.chainbill.bill.biz.transfer.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.message.keyword.XfeApplyKeyword;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbXfe;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.stereotype.Component;

@Component
public class BillXfeMsgSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbXfe>> {
	public void onApplicationEvent(BillEvent<CbXfe> t) {
		CbRec cbRec = t.getBill().getRec();
		CbXfe cbXfe = (CbXfe) t.getBill().getSource();

		String template = "MT01401";
		XfeApplyKeyword keyWord = new XfeApplyKeyword();
		keyWord.setBillAmt(String.valueOf(cbRec.getBillAmt()));
		keyWord.setContactorName(CommonDataUtil.getUserName());

		String xfeDate = SysDateUtil.parseDate(cbXfe.getXfeDate(), "yyyyMMdd", "yyyy-MM-dd");
		keyWord.setXfeDate(xfeDate);

		keyWord.setSellerNm(cbXfe.getSellerNm());

		String senderId = CommonDataUtil.getUserId();

		MessageSender.sendMessageByTmpl(senderId, template, keyWord, cbXfe.getBuyerId());
	}
}
